package com.atguigu.spzx.manager.controller;


import com.atguigu.spzx.common.log.annotation.Log;
import com.atguigu.spzx.common.log.enums.OperatorType;
import com.atguigu.spzx.manager.service.BrandService;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.entity.system.SysUser;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 分类品牌(Brand)表控制层
 *
 * @author makejava
 * @since 2024-03-20 11:55:50
 */
@RestController
@RequestMapping("/admin/product/brand")
public class BrandController{
    /**
     * 服务对象
     */
    @Autowired
    private BrandService brandService;

    @GetMapping("/findAll")
    public Result findAll() {
        List<Brand> list = brandService.findAll();
        return Result.build(list , ResultCodeEnum.SUCCESS) ;
    }

    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Long id){
        brandService.deleteById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @PutMapping("/updateById")
    public Result UpdateBrandById(@RequestBody Brand brand){
        brandService.UpdateBrandById(brand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/save")
    public Result SaveBrand(@RequestBody Brand brand){
        brandService.saveBrand(brand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @Log(title = "品牌管理：列表",businessType = 0,operatorType = OperatorType.OTHER)
    @GetMapping("/{pageNum}/{pageSize}")
    public Result GetBrandPageList(@PathVariable Integer pageNum,
                                   @PathVariable Integer pageSize){
        PageInfo<Brand> pageInfo = brandService.GetBrandPageList(pageNum,pageSize);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }


}

